package com.online.service_edu.controller;


import com.online.common_utils.ResultJson;
import com.online.service_edu.entity.EduVideo;
import com.online.service_edu.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author hdc2008
 * @since 2021-02-11
 */
@RestController
@RequestMapping("/service_edu/video")
@CrossOrigin
public class EduVideoController {

    @Autowired
    private EduVideoService eduVideoService;

    @PostMapping("addVideo")
    public ResultJson addVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.save(eduVideo);
        return ResultJson.ok();
    }

    @GetMapping("getVideoById/{id}")
    public ResultJson getVideoById(@PathVariable String id){
        EduVideo eduVideo = eduVideoService.getById(id);
        return ResultJson.ok().data("video",eduVideo);
    }

    @PostMapping("updateVideo")
    public ResultJson updateVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.updateById(eduVideo);
        return ResultJson.ok();
    }

    @GetMapping("delete/{id}")
    public ResultJson deleteVideoById(@PathVariable String id){
        boolean flag=eduVideoService.removeVideo(id);
        if(flag){
            return ResultJson.ok();
        }else{
            return ResultJson.error().message("删除小节失败");
        }
    }
    @GetMapping("removeIdName/{id}")
    public ResultJson removeIdName(@PathVariable String id){
        boolean flag=eduVideoService.removeSoureVideoIdAndName(id);
        return ResultJson.ok();
    }

}

